package com.itheima.test;

import cn.hutool.core.collection.CollUtil;
import org.junit.Test;

import java.util.*;

public class tezt {
    @Test
    public void text(){
        //创建list集合
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        List<Integer> list2 = Arrays.asList(1,2,3,6,8,0);

        List<Integer> list3 = CollUtil.newArrayList(1,2,3,5,7);
        //1：多个集合取交集方法
        Collection<Integer> intersection = CollUtil.intersection(list1, list2);
        Collection<Integer> intersection2 = CollUtil.intersection(list3, list2);
        Collection<Integer> intersection3 = CollUtil.intersection(list3, list2,list1);

        System.out.println(intersection);
        System.out.println(intersection2);
        System.out.println(intersection3);
        //2：取并集方法
        Collection<Integer> union = CollUtil.union(list3, list2, list1);
        System.out.println(union);
        //3:取集合中的 最大最小值
        Integer max = CollUtil.max(list1);
        Integer min = CollUtil.min(list1);
        System.out.println("最大值"+max);
        System.out.println("最小值"+min);
    }
    //集合排序
    @Test
    public void text2(){
        ArrayList<String> list1 = CollUtil.newArrayList("8","3","4","6");
        ArrayList<Integer> list2 = CollUtil.newArrayList(8,1,2,3,4,5);
        //自定义排序规则
        CollUtil.sort(list1,String::compareTo);
        CollUtil.sort(list2,Integer::compareTo);
        System.out.println(list1);
        System.out.println(list2);

        Collections.sort(list1);
        System.out.println(list1);
    }
}
